package business
{
	import com.adobe.cairngorm.business.ServiceLocator;
	
	import mx.collections.ItemResponder;
	import mx.rpc.AsyncToken;
	import mx.rpc.remoting.RemoteObject;
	
	public class EventDelegate
	{
		private var responder:Object;
        private var service:RemoteObject;
        		
		public function EventDelegate(re:Object)
		{
	        this.service = ServiceLocator.getInstance().getRemoteObject("eventService");
            this.responder = re;			
		}
		
        public function getAllEvents():void
        {
            var token:AsyncToken;
            var itemResponder:ItemResponder;
            token = service.getAllEvents();
            itemResponder = new ItemResponder(responder["getAllEventsResult"],responder["fault"] );
            token.addResponder(itemResponder);
        }
        
        public function addEvent(items:Object):void
        {
            var token:AsyncToken;
            var itemResponder:ItemResponder;
            token = service.addEvent(items);
            itemResponder = new ItemResponder(responder["addEventResult"],responder["fault"] );
            token.addResponder(itemResponder);
        } 
        
        public function update(items:Object):void
        {
            var token:AsyncToken;
            var itemResponder:ItemResponder;
            token = service.update(items);
            itemResponder = new ItemResponder(responder["updateResult"],responder["fault"] );
            token.addResponder(itemResponder);
        }
        
        public function delEventById(id:int):void
        {
            var token:AsyncToken;
            var itemResponder:ItemResponder;
            token = service.delEventById(id);
            itemResponder = new ItemResponder(responder["delEventByIdResult"],responder["fault"] );
            token.addResponder(itemResponder);
        } 
        
        public function search(item:Object):void
        {
            var token:AsyncToken;
            var itemResponder:ItemResponder;
            token = service.search(item);
            itemResponder = new ItemResponder(responder["searchResult"],responder["fault"] );
            token.addResponder(itemResponder);       	
        }
        
        public function getEvent(page:int, row:int=10, sort:String='id'):void
        {
            var token:AsyncToken;
            var itemResponder:ItemResponder;
            token = service.getEvent(page, row, sort);
            itemResponder = new ItemResponder(responder["getEventResult"],responder["fault"] );
            token.addResponder(itemResponder);          
        }                

		public function sentIsShow(eventId:String,isShow:Boolean):void
		{
			var token:AsyncToken;
			var itemResponder:ItemResponder;
			token = service.sentIsShow(eventId, isShow.toString());
			itemResponder = new ItemResponder(responder["sentIsShowResult"], responder["fault"]);
			token.addResponder(itemResponder);
		}
		
		public function addBigMaker(items:Object):void
		{
			var token:AsyncToken;
			var itemResponder:ItemResponder;
			token = service.addToZhizuo(items);
			itemResponder = new ItemResponder(responder["addBigMakerResult"], responder["fault"]);
			token.addResponder(itemResponder);
		}
	}
}